﻿using ConsoleApp.Infrastructure.Rmq;
using ConsoleApp.Infrastructure.TaskFramework;
using ConsoleApp.Job.Model.Response;
using ConsoleApp.Util;
using System;

namespace ConsoleApp.Job.TaskJob.队列消费
{
    public class RmqMaxwell_Product消费任务 : TaskBase
    {
        /// <summary>
        /// QueneName
        /// </summary>
        public static string RmqMaxwell_Product_Quene
        {
            get
            {
                return "maxwell_product_t1";
            }
        }

        /// <summary>
        /// Msg
        /// </summary>
        public class Product_Msg
        {
            public int Id { get; set; }

            public string Name { get; set; }
        }

        /// <summary>
        /// Execute
        /// </summary>
        public override void Execute()
        {
            while (true)
            {
                new RmqMaxwell_Product消费任务_RMQ(RmqQueueManager.Connect, RmqMaxwell_Product_Quene).HandleOneMessage();
            }
        }

        /// <summary>
        /// Consumer
        /// </summary>
        public class RmqMaxwell_Product消费任务_RMQ : OneConsumerWorkerBase<MaxwellResponse<Product_Msg>>
        {
            public RmqMaxwell_Product消费任务_RMQ(RmqOption connection, string queueName) : base(connection)
            {
                Console.Title = queueName;
                QueueName = queueName;
            }

            protected override bool HandleComingMessage(MaxwellResponse<Product_Msg> msg)
            {
                ConsoleHelper.WriteWarningLine($@"
                                                  RmqMaxwell_Product消费任务!!
                                                  Maxwell database:{msg.database},
                                                  Maxwell table:{msg.table},
                                                  Maxwell type:{msg.type},
                                                  Maxwell data.Name:{msg.data.Name}");
                return true;
            }
        }
    }
}
